//
//  LKUploadFileViewController.m
//  YLHelper
//
//  Created by she1323 on 2018/5/4.
//  Copyright © 2018年 she1323. All rights reserved.
//

#import "LKUploadFileViewController.h"
#import "LKPictureDeleteOrAddCell.h"
#import "HXPhotoPicker.h"
#import "LKPictureDeleteOrAddModel.h"
#import "LKOrderEditTopView.h"
#import "LKCustomerAttachModel.h"
#import "LKWorkOrderUpdateViewController.h"
#import "UIImage+RecordID.h"
@interface LKUploadFileViewController ()<UITableViewDelegate,UITableViewDataSource>{
            dispatch_group_t group;

}
@property(nonatomic,strong)LKBaseTableview *tableview;
@property (strong, nonatomic) HXDatePhotoToolManager *toolManager;
@property (strong, nonatomic) NSMutableArray *picdataArray;
@property(nonatomic,strong)NSArray *titlesArray;
@property(nonatomic,strong)UIButton *btn;
@property (nonatomic, strong) NSMutableArray *waitArray;
@property (nonatomic, strong) NSMutableArray *completeArray;
@property(nonatomic,strong)NSMutableArray *OrderAttachs1;//合同首页数组
@property(nonatomic,strong)NSMutableArray *OrderAttachs2;//合同详情数组
@property(nonatomic,strong)NSMutableArray *OrderAttachs3;//POS凭证数组
@property(nonatomic,strong)NSMutableArray *OrderAttachs0;//其他数组
@property(nonatomic,strong)NSMutableArray *OrderAttachsModel1;//合同首页数组
@property(nonatomic,strong)NSMutableArray *OrderAttachsModel2;//合同详情数组
@property(nonatomic,strong)NSMutableArray *OrderAttachsModel3;//POS凭证数组
@property(nonatomic,strong)NSMutableArray *OrderAttachsModel0;//其他数组
@end

@implementation LKUploadFileViewController
- (HXDatePhotoToolManager *)toolManager {
    if (!_toolManager) {
        _toolManager = [[HXDatePhotoToolManager alloc] init];
    }
    return _toolManager;
}
-(LKBaseTableview *)tableview{
    if (!_tableview) {
        _tableview = [LKBaseTableview setTableviewWithFrame:CGRectMake(0, NAVIGATION_BAR_HEIGHT, WIDTH, HEIGHT - NAVIGATION_BAR_HEIGHT) style:UITableViewStylePlain registercellClasss:@[]];
        [_tableview registerClass:[LKPictureDeleteOrAddCell class] forCellReuseIdentifier:@"LKPictureDeleteOrAddCell"];
        [self.view addSubview:_tableview];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        _tableview.emptyDataSetDelegate = self;
        _tableview.emptyDataSetSource = self;
        _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableview.estimatedRowHeight = 200;
    }
    return _tableview;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    group = dispatch_group_create();
    self.picdataArray = [[NSMutableArray alloc] init];
    if (self.isOrderUpdate) {
        for (int i = 0; i < 5; i++) {
            LKPictureDeleteOrAddModel *model = [[LKPictureDeleteOrAddModel alloc] init];
            if (i == 0) {
                NSMutableArray *attach1 = [[NSMutableArray alloc] init];
                for (NSDictionary *dic in self.addOrderModel.OrderAttachs1) {
                    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ServerlUrl,dic[@"AttachUrl"]]]]];
                    if (image == nil) {
                        image = [UIImage imageNamed:@"pic"];
                    }
                    image.recordId = [NSString stringWithFormat:@"%@",dic[@"Id"]];
                    image.recordfileUrl = [NSString stringWithFormat:@"%@",dic[@"AttachUrl"]];
                    NSLog(@"%@",image.recordId);
                    [attach1 addObject:image];
                }
                NSMutableArray *foreImages = [[NSMutableArray alloc] init];
                for (UIImage *subimage in attach1) {
                    HXPhotoModel *model = [HXPhotoModel photoModelWithImage:subimage];
                    model.fuckId = subimage.recordId;
                    model.fuckRecordUrl = subimage.recordfileUrl;
                    [foreImages addObject:model];
                }
                model.endSelectedList = foreImages.mutableCopy;
            }
            
            if (i == 1) {
                NSMutableArray *attach1 = [[NSMutableArray alloc] init];
                for (NSDictionary *dic in self.addOrderModel.OrderAttachs2) {
                    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ServerlUrl,dic[@"AttachUrl"]]]]];
                    if (image == nil) {
                        image = [UIImage imageNamed:@"pic"];
                    }
                    image.recordId = [NSString stringWithFormat:@"%@",dic[@"Id"]];
                    image.recordfileUrl = [NSString stringWithFormat:@"%@",dic[@"AttachUrl"]];
                    [attach1 addObject:image];
                }
                NSMutableArray *foreImages = [[NSMutableArray alloc] init];
                for (UIImage *subimage in attach1) {
                    HXPhotoModel *model = [HXPhotoModel photoModelWithImage:subimage];
                    model.fuckId = subimage.recordId;
                    model.fuckRecordUrl = subimage.recordfileUrl;
                    [foreImages addObject:model];
                }
                model.endSelectedList = foreImages.mutableCopy;
                
            }
            if (i == 2) {
                NSMutableArray *attach1 = [[NSMutableArray alloc] init];
                for (NSDictionary *dic in self.addOrderModel.OrderAttachs3) {
                    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ServerlUrl,dic[@"AttachUrl"]]]]];
                    if (image == nil) {
                        image = [UIImage imageNamed:@"pic"];
                    }
                    image.recordId = [NSString stringWithFormat:@"%@",dic[@"Id"]];
                    image.recordfileUrl = [NSString stringWithFormat:@"%@",dic[@"AttachUrl"]];
                    [attach1 addObject:image];
                }
                NSMutableArray *foreImages = [[NSMutableArray alloc] init];
                for (UIImage *subimage in attach1) {
                    HXPhotoModel *model = [HXPhotoModel photoModelWithImage:subimage];
                    model.fuckId = subimage.recordId;
                    model.fuckRecordUrl = subimage.recordfileUrl;
                    [foreImages addObject:model];
                }
                model.endSelectedList = foreImages.mutableCopy;
                
            }
            if (i == 3) {
                NSMutableArray *attach1 = [[NSMutableArray alloc] init];
                for (NSDictionary *dic in self.addOrderModel.OrderAttachs0) {
                    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ServerlUrl,dic[@"AttachUrl"]]]]];
                    if (image == nil) {
                        image = [UIImage imageNamed:@"pic"];
                    }
                    image.recordId = [NSString stringWithFormat:@"%@",dic[@"Id"]];
                    image.recordfileUrl = [NSString stringWithFormat:@"%@",dic[@"AttachUrl"]];
                    [attach1 addObject:image];
                }
                NSMutableArray *foreImages = [[NSMutableArray alloc] init];
                for (UIImage *subimage in attach1) {
                    HXPhotoModel *model = [HXPhotoModel photoModelWithImage:subimage];
                    model.fuckId = subimage.recordId;
                    model.fuckRecordUrl = subimage.recordfileUrl;
                    [foreImages addObject:model];
                }
                model.endSelectedList = foreImages.mutableCopy;  
            }
            [self.picdataArray addObject:model];
        }
    }else{
        for (int i = 0; i < 5; i++) {
            LKPictureDeleteOrAddModel *model = [[LKPictureDeleteOrAddModel alloc] init];
            [self.picdataArray addObject:model];
        }
    }

    [self.tableview reloadData];
    // Do any additional setup after loading the view.
}
-(void)setNavgationBackBtn{
    [super setNavgationBackBtn];
    self.navigationItem.title = @"上传附件";
    _btn = [UIButton buttonWithType:UIButtonTypeCustom];
    _btn.titleLabel.font = [UIFont systemFontOfSize:16];
    [_btn setTitle:@"提交" forState:UIControlStateNormal];
    [_btn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateDisabled];
    [_btn setTitleColor:blueDefault forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_btn];
    [_btn addTarget:self action:@selector(submitPicture:) forControlEvents:UIControlEventTouchUpInside];
    if (self.isOrderUpdate) {
//        btn.hidden = YES;
        [_btn setTitle:@"保存" forState:UIControlStateNormal];
    }
}
//-(void)back{
//    if (self.isOrderUpdate) {
//        [self submitPicture:nil];
//    }else{
//        [super back];
//    }
//}

/**
 提交附件
 */
-(void)submitPicture:(UIButton *)btn{
//        if (self.isOrderUpdate) {
//            [self submitPicture:nil];
//            return;
//        }
//    _btn.enabled = NO;
    if ([btn.titleLabel.text isEqual:@"提交"]) {
        _btn.enabled = NO;
    }
    self.completeArray = [NSMutableArray array];
    self.waitArray = [[NSMutableArray alloc] init];
    [self.waitArray addObjectsFromArray:self.picdataArray];
//    self.waitArray = [NSMutableArray arrayWithArray:self.picdataArray];
    [self.view showLoadingHUDText:@"提交中..."];
    [self startUpload];
}
-(void)startUpload{
    WS(weakSelf)
    if (self.waitArray.count == 0) {
        [self.view handleLoading];
        NSSLog(@"全部写入完毕");
//        dispatch_group_t group = dispatch_group_create();
        dispatch_group_enter(group);
        if (self.OrderAttachs1.count == 0) {
             dispatch_group_leave(group);
        }else{
            for (NSInteger i = 0; i < self.OrderAttachs1.count; i++) {
                UIImage *image = self.OrderAttachs1[i];
                if (image.recordId) {
                    LKCustomerAttachModel *attachModel = [[LKCustomerAttachModel alloc] init];
                    attachModel.AttachName = @"image.png";
                    attachModel.AttachUrl = image.recordfileUrl;
                    attachModel.Suffix = @".png";
                    attachModel.OrderAttachCategory = @"1";
                    attachModel.Id = image.recordId;
                    NSDictionary *dic = [attachModel properties_aps];
                    [weakSelf.OrderAttachsModel1 addObject:dic];
                    if (weakSelf.OrderAttachsModel1.count == self.OrderAttachs1.count) {
                        dispatch_group_leave(group);
                    }
                    continue;
                }
                NSLog(@"gogo=%@",image.recordId);
                [[LKNetDataManager defaultManager] sendPOSTRequestWithserverUrl:ServerlUrl apiPath:orderOfPictureUrl parameters:nil imageArray:@[image] targetWidth:100 progress:^(NSProgress * _Nullable progress) {
                    
                } success:^(BOOL isSuccess, id  _Nullable responseObject) {
                    
                    LKCustomerAttachModel *attachModel = [[LKCustomerAttachModel alloc] init];
                    attachModel.AttachName = responseObject[@"fileName"];
                    attachModel.AttachUrl = responseObject[@"fileUrl"];
                    attachModel.Suffix = responseObject[@"suffix"];
                    attachModel.OrderAttachCategory = @"1";
                    attachModel.Id = image.recordId;
                    NSDictionary *dic = [attachModel properties_aps];
                    [weakSelf.OrderAttachsModel1 addObject:dic];
                    if (weakSelf.OrderAttachsModel1.count == self.OrderAttachs1.count) {
                        dispatch_group_leave(group);
                        NSLog(@"任务组1完成");
                    }
                } failure:^(NSString * _Nullable error) {
                       dispatch_group_leave(group);
                }];
            }
        }
        dispatch_group_enter(group);
        if (self.OrderAttachs2.count == 0) {
            NSLog(@"任务组2完成");
            dispatch_group_leave(group);
        }else{
            for (NSInteger i = 0; i < self.OrderAttachs2.count; i++) {
                UIImage *image = self.OrderAttachs2[i];
                if (image.recordId) {
                    LKCustomerAttachModel *attachModel = [[LKCustomerAttachModel alloc] init];
                    attachModel.AttachName = @"image.png";
                    attachModel.AttachUrl = image.recordfileUrl;
                    attachModel.Suffix = @".png";
                    attachModel.OrderAttachCategory = @"2";
                    attachModel.Id = image.recordId;
                    NSDictionary *dic = [attachModel properties_aps];
                    [weakSelf.OrderAttachsModel2 addObject:dic];
                    if (weakSelf.OrderAttachsModel2.count == self.OrderAttachs2.count) {
                        dispatch_group_leave(group);
                    }
                    continue;
                }
                [[LKNetDataManager defaultManager] sendPOSTRequestWithserverUrl:ServerlUrl apiPath:orderOfPictureUrl parameters:nil imageArray:@[image] targetWidth:100 progress:^(NSProgress * _Nullable progress) {
                    
                } success:^(BOOL isSuccess, id  _Nullable responseObject) {
                    
                    LKCustomerAttachModel *attachModel = [[LKCustomerAttachModel alloc] init];
                    attachModel.AttachName = responseObject[@"fileName"];
                    attachModel.AttachUrl = responseObject[@"fileUrl"];
                    attachModel.Suffix = responseObject[@"suffix"];
                    attachModel.OrderAttachCategory = @"2";
                    NSDictionary *dic = [attachModel properties_aps];
                    [weakSelf.OrderAttachsModel2 addObject:dic];
                    if (weakSelf.OrderAttachsModel2.count == self.OrderAttachs2.count) {
                        dispatch_group_leave(group);
                    }
                } failure:^(NSString * _Nullable error) {
                     dispatch_group_leave(group);
                }];
            }
        }
        dispatch_group_enter(group);
        if (self.OrderAttachs3.count == 0) {
            NSLog(@"任务组3完成");
            dispatch_group_leave(group);
        }else{
            for (NSInteger i = 0; i < self.OrderAttachs3.count; i++) {
                UIImage *image = self.OrderAttachs3[i];
                if (image.recordId) {
                    LKCustomerAttachModel *attachModel = [[LKCustomerAttachModel alloc] init];
                    attachModel.AttachName = @"image.png";
                    attachModel.AttachUrl = image.recordfileUrl;
                    attachModel.Suffix = @".png";
                    attachModel.OrderAttachCategory = @"3";
                    attachModel.Id = image.recordId;
                    NSDictionary *dic = [attachModel properties_aps];
                    [weakSelf.OrderAttachsModel3 addObject:dic];
                    if (weakSelf.OrderAttachsModel3.count == self.OrderAttachs3.count) {
                        dispatch_group_leave(group);
                    }
                    continue;
                }
                [[LKNetDataManager defaultManager] sendPOSTRequestWithserverUrl:ServerlUrl apiPath:orderOfPictureUrl parameters:nil imageArray:@[image] targetWidth:100 progress:^(NSProgress * _Nullable progress) {
                    
                } success:^(BOOL isSuccess, id  _Nullable responseObject) {
                    
                    LKCustomerAttachModel *attachModel = [[LKCustomerAttachModel alloc] init];
                    attachModel.AttachName = responseObject[@"fileName"];
                    attachModel.AttachUrl = responseObject[@"fileUrl"];
                    attachModel.Suffix = responseObject[@"suffix"];
                    attachModel.OrderAttachCategory = @"3";
                    NSDictionary *dic = [attachModel properties_aps];
                    [weakSelf.OrderAttachsModel3 addObject:dic];
                    if (weakSelf.OrderAttachsModel3.count == self.OrderAttachs3.count) {
                        dispatch_group_leave(group);
                    }
                } failure:^(NSString * _Nullable error) {
                     dispatch_group_leave(group);
                }];
            }
        }
         dispatch_group_enter(group);
        if (self.OrderAttachs0.count == 0) {
            NSLog(@"任务组4完成");
         dispatch_group_leave(group);
        }else{
            for (NSInteger i = 0; i < self.OrderAttachs0.count; i++) {
                UIImage *image = self.OrderAttachs0[i];
                if (image.recordId) {
                    LKCustomerAttachModel *attachModel = [[LKCustomerAttachModel alloc] init];
                    attachModel.AttachName = @"image.png";
                    attachModel.AttachUrl = image.recordfileUrl;
                    attachModel.Suffix = @".png";
                    attachModel.OrderAttachCategory = @"0";
                    attachModel.Id = image.recordId;
                    NSDictionary *dic = [attachModel properties_aps];
                    [weakSelf.OrderAttachsModel0 addObject:dic];
                    if (weakSelf.OrderAttachsModel0.count == self.OrderAttachs0.count) {
                        dispatch_group_leave(group);
                    }
                    continue;
                }
                [[LKNetDataManager defaultManager] sendPOSTRequestWithserverUrl:ServerlUrl apiPath:orderOfPictureUrl parameters:nil imageArray:@[image] targetWidth:100 progress:^(NSProgress * _Nullable progress) {
                    
                } success:^(BOOL isSuccess, id  _Nullable responseObject) {
                    
                    LKCustomerAttachModel *attachModel = [[LKCustomerAttachModel alloc] init];
                    attachModel.AttachName = responseObject[@"fileName"];
                    attachModel.AttachUrl = responseObject[@"fileUrl"];
                    attachModel.Suffix = responseObject[@"suffix"];
                    attachModel.OrderAttachCategory = @"0";
                    NSDictionary *dic = [attachModel properties_aps];
                    [weakSelf.OrderAttachsModel0 addObject:dic];
                    if (weakSelf.OrderAttachsModel0.count == self.OrderAttachs0.count) {
                        dispatch_group_leave(group);
                        
                    }
                } failure:^(NSString * _Nullable error) {
                     dispatch_group_leave(group);
                }];
            }
        }
       
        dispatch_group_notify(group, dispatch_get_main_queue(), ^{
            [weakSelf.view handleLoading];
            _btn.enabled = YES;
            NSLog(@"第一个集合%@",weakSelf.OrderAttachsModel1);
            NSLog(@"第二个集合%@",weakSelf.OrderAttachsModel2);
            NSLog(@"第三个集合%@",weakSelf.OrderAttachsModel3);
            NSLog(@"第四个集合%@",weakSelf.OrderAttachsModel0);
            weakSelf.addOrderModel.OrderAttachs1 = weakSelf.OrderAttachsModel1;
            weakSelf.addOrderModel.OrderAttachs2 = weakSelf.OrderAttachsModel2;
            weakSelf.addOrderModel.OrderAttachs3 = weakSelf.OrderAttachsModel3;
            weakSelf.addOrderModel.OrderAttachs0 = weakSelf.OrderAttachsModel0;
            if (weakSelf.isOrderUpdate) {
                if (weakSelf.sendAddOrderBlock) {
              weakSelf.sendAddOrderBlock(weakSelf.addOrderModel);
                    [self.navigationController popViewControllerAnimated:YES];
                    return;
                }
            }
            LKWorkOrderUpdateViewController *vc = [[LKWorkOrderUpdateViewController alloc] init];
            vc.theme = @"再次核对订单信息";
            WS(weakSelf)
            [vc.backClearSub subscribeNext:^(id  _Nullable x) {
               SS(strongSelf)
                [strongSelf.picdataArray removeAllObjects];
                for (int i = 0; i < 5; i++) {
                    LKPictureDeleteOrAddModel *model = [[LKPictureDeleteOrAddModel alloc] init];
                    if (i == 0) {
                        NSMutableArray *attach1 = [[NSMutableArray alloc] init];
                        for (UIImage *img in strongSelf.OrderAttachs1) {
                            HXPhotoModel *photoModel = [HXPhotoModel photoModelWithImage:img];
                            [attach1 addObject:photoModel];
                        }
                        model.endSelectedList = attach1;
                    }

                    if (i == 1) {
                        NSMutableArray *attach1 = [[NSMutableArray alloc] init];
                        for (UIImage *img in strongSelf.OrderAttachs2) {
                            HXPhotoModel *photoModel = [HXPhotoModel photoModelWithImage:img];
                            [attach1 addObject:photoModel];
                        }
                        model.endSelectedList = attach1;
                    }
                    if (i == 2) {
                        NSMutableArray *attach1 = [[NSMutableArray alloc] init];
                        for (UIImage *img in strongSelf.OrderAttachs3) {
                            HXPhotoModel *photoModel = [HXPhotoModel photoModelWithImage:img];
                            [attach1 addObject:photoModel];
                        }
                        model.endSelectedList = attach1;
                    }
                    if (i == 3) {
                        NSMutableArray *attach1 = [[NSMutableArray alloc] init];
                        for (UIImage *img in strongSelf.OrderAttachs0) {
                            HXPhotoModel *photoModel = [HXPhotoModel photoModelWithImage:img];
                            [attach1 addObject:photoModel];
                        }
                        model.endSelectedList = attach1;
                    }
                    
                    [strongSelf.picdataArray addObject:model];
                }
                [strongSelf.tableview reloadData];
                
                [strongSelf.OrderAttachs1 removeAllObjects];
                [strongSelf.OrderAttachs2 removeAllObjects];
                [strongSelf.OrderAttachs3 removeAllObjects];
                [strongSelf.OrderAttachs0 removeAllObjects];
                [strongSelf.OrderAttachsModel1 removeAllObjects];
                [strongSelf.OrderAttachsModel2 removeAllObjects];
                [strongSelf.OrderAttachsModel3 removeAllObjects];
                [strongSelf.OrderAttachsModel0 removeAllObjects];
            }];
 //*********************************************************//
            
            [vc.OrderAttachsModel0 addObjectsFromArray:weakSelf.OrderAttachsModel0];
            [vc.OrderAttachsModel1 addObjectsFromArray:weakSelf.OrderAttachsModel1];
            [vc.OrderAttachsModel2 addObjectsFromArray:weakSelf.OrderAttachsModel2];
            [vc.OrderAttachsModel3 addObjectsFromArray:weakSelf.OrderAttachsModel3];
            vc.addOrderModel = weakSelf.addOrderModel;
            [weakSelf.navigationController pushViewController:vc animated:YES];
            return;
        });
        return;
    }
    __block LKPictureDeleteOrAddModel *model = self.waitArray.firstObject;
    if (model.endSelectedList.count > 0) {
        [self.waitArray removeObjectAtIndex:0];
        [self.toolManager getSelectedImageList:model.endSelectedList success:^(NSArray<UIImage *> *imageList) {
            NSLog(@"第%ld个cell/n%@",[weakSelf.picdataArray indexOfObject:model],imageList);
            for (UIImage *imag in imageList) {
                NSLog(@"%@",imag.recordId);
            }
            switch ([weakSelf.picdataArray indexOfObject:model]) {
                case 0:
                {
                    [weakSelf.OrderAttachs1 addObjectsFromArray:imageList];
                }
                    break;
                case 1:
                {
                    [weakSelf.OrderAttachs2 addObjectsFromArray:imageList];
                }
                    break;
                case 2:
                {
                    [weakSelf.OrderAttachs3 addObjectsFromArray:imageList];
                }
                    break;
                case 3:
                {
                    [weakSelf.OrderAttachs0 addObjectsFromArray:imageList];
                }
                    break;
                default:
                    break;
            }
            [weakSelf startUpload];
        } failed:^{
            
        }];

    }else {
        [self.waitArray removeObjectAtIndex:0];
        [self startUpload];
        return;
    }
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.titlesArray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LKPictureDeleteOrAddCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKPictureDeleteOrAddCell"];
    cell.model = self.picdataArray[indexPath.section];
    __weak typeof(self) weakSelf = self;
    [cell setPhotoViewChangeHeightBlock:^(UITableViewCell *mycell) {
        [weakSelf.tableview reloadRowsAtIndexPaths:@[[weakSelf.tableview indexPathForCell:mycell]] withRowAnimation:0];
    }];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    LKPictureDeleteOrAddModel *model = self.picdataArray[indexPath.section];
    return model.cellHeight;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    LKOrderEditTopView *topView = [[[NSBundle mainBundle] loadNibNamed:@"LKOrderEditTopView" owner:self options:nil] lastObject];
    [topView.leftBtn setTitle:self.titlesArray[section] forState:UIControlStateNormal];
    [topView.leftBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [topView.rightBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [topView.rightBtn setTitle:@"" forState:UIControlStateNormal];
//    topView.rightBtn.tag = 10000 + section;
    return topView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 43;
}
-(NSArray *)titlesArray{
    if (!_titlesArray) {
        if (self.fileType == 0) {
          _titlesArray = @[@"合同首页",@"合同详情",@"POS凭证",@"其他"];
        }else{
            _titlesArray = @[@"POS凭证",@"其他"];
        }
    }
    return _titlesArray;
}
-(NSMutableArray *)OrderAttachs0{
    if (!_OrderAttachs0) {
        _OrderAttachs0 = [[NSMutableArray alloc] init];
    }
    return _OrderAttachs0;
}
-(NSMutableArray *)OrderAttachs1{
    if (!_OrderAttachs1) {
        _OrderAttachs1 = [[NSMutableArray alloc] init];
    }
    return _OrderAttachs1;
}
-(NSMutableArray *)OrderAttachs2{
    if (!_OrderAttachs2) {
        _OrderAttachs2 = [[NSMutableArray alloc] init];
    }
    return _OrderAttachs2;
}
-(NSMutableArray *)OrderAttachs3{
    if (!_OrderAttachs3) {
        _OrderAttachs3 = [[NSMutableArray alloc] init];
    }
    return _OrderAttachs3;
}
-(NSMutableArray *)OrderAttachsModel0{
    if (!_OrderAttachsModel0) {
        _OrderAttachsModel0 = [[NSMutableArray alloc] init];
    }
    return _OrderAttachsModel0;
}
-(NSMutableArray *)OrderAttachsModel1{
    if (!_OrderAttachsModel1) {
        _OrderAttachsModel1 = [[NSMutableArray alloc] init];
    }
    return _OrderAttachsModel1;
}
-(NSMutableArray *)OrderAttachsModel2{
    if (!_OrderAttachsModel2) {
        _OrderAttachsModel2 = [[NSMutableArray alloc] init];
    }
    return _OrderAttachsModel2;
}
-(NSMutableArray *)OrderAttachsModel3{
    if (!_OrderAttachsModel3) {
        _OrderAttachsModel3 = [[NSMutableArray alloc] init];
    }
    return _OrderAttachsModel3;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
